<?php 
namespace Home\Controller;

use Think\Controller;

class LoginController extends Controller{

	/**
	 * 后台用户用户登录
	 */
	public function login(){
		if(session(C('ADMIN_USER_SESSION_KEY') . '_id')){
			$this->redirect( MODULE_NAME . '/Index/index');
		}
		$this->display();
	}

	/**
	 * 登陆处理程序
	 */
	public function login_check(){
		if(!IS_POST){
			$this->error('请求失败');
		}
		$admin_model = D('admin');

		$con = array(
				'name' => I('post.name'),
				'pwd' => I('post.pwd')
			);
		$admin_res = $admin_model->get_admin_info($con);
		if(is_array($admin_res) && $admin_res['status']){
			//登陆成功
			session(C('ADMIN_USER_SESSION_KEY') . '_id' , $admin_res['msg']['id']);
			session(C('ADMIN_USER_SESSION_KEY') . '_name' , $admin_res['msg']['name']);
			$this->redirect( MODULE_NAME . '/Index/index');
		}else{
			$this->error($admin_res['msg']);
		}
	}
}
 ?>